package com.salmon.test;

import com.salmon.common.utils.JsonUtils;
import com.salmon.weixin.menu.Button;
import com.salmon.weixin.menu.ClickButton;
import com.salmon.weixin.menu.Menu;
import com.salmon.weixin.menu.ViewButton;
import com.salmon.weixin.po.AccessToken;
import com.salmon.weixin.po.MenuResult;
import com.salmon.weixin.utils.WeixinUtils;
import org.junit.Test;

public class WeiXin {

    @Test
    public void obtainAccessToken() {
       AccessToken accessToken = WeixinUtils.getAccessToken();
       System.out.println(JsonUtils.toJson(accessToken));
    }


    /**
     * 组装菜单
     * @return
     */
    private Menu initMenu(){
        Menu menu = new Menu();
        ClickButton button11 = new ClickButton();
        button11.setName("click菜单");
        button11.setType("click");
        button11.setKey("11");

        ViewButton button21 = new ViewButton();
        button21.setName("view菜单");
        button21.setType("view");
        button21.setUrl("http://www.imooc.com");

        ClickButton button31 = new ClickButton();
        button31.setName("扫码事件");
        button31.setType("scancode_push");
        button31.setKey("31");

        ClickButton button32 = new ClickButton();
        button32.setName("地理位置");
        button32.setType("location_select");
        button32.setKey("32");

        Button button = new Button();
        button.setName("菜单");
        button.setSub_button(new Button[]{button31,button32});

        menu.setButton(new Button[]{button11,button21,button});
        return menu;
    }

    @Test
    public void createMenu() {
        String accessToken = "14_GXuuYLNuxYJ5ErCQVlrxBdayzhRD4TEHK3n4YHc_IKc0y8-S5GazoOpyAjJSZs04YYVKGgNE_UsNQxXHzqQk8_adNmzJZAyNSoLye3Yvlq_HPa0C-sUzsuUk13o65SFZkbox3gUDKQzw8e67ZCBbAAAQTS";
        MenuResult result = WeixinUtils.createMenu(accessToken,JsonUtils.toJson(initMenu()));
        System.out.println(JsonUtils.toJson(result));
    }

}
